﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{

    public class GreigeMasterData : BaseFunction
    {
        public GreigeMasterData()
            : base()
        {

        }
        public GreigeMasterData(OracleConnection _OracleDB, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_OracleDB, _proxy, userID)
        {

        }
        public DataSet LoadTableStructure(DataSet dsTarget)
        {
            try
            {
                TableQueue.Enqueue("WAFARBEN");
                TableQueue.Enqueue("SELECT WAFART as ArtNum,	WAFVAR as ArtVar,	 WAFZUSATZ as ArtColor,WAFBEZ as ColorDescription"
                    + "  FROM INTEX.WAFARBEN WHERE RowNum<1");
                TableQueue.Enqueue("BSSATZ");
                TableQueue.Enqueue("SELECT  "
                    + "BSKART"
                    + ",BSFDZ"
                    + ",BSSRFNR"
                    + ",BSFAKTOR"
                   + " FROM INTEX.BSSATZ WHERE RowNum<1");
                TableQueue.Enqueue("BASTKE");
                TableQueue.Enqueue("SELECT "
                              + "BAKART"
               + ",BAKVAR"
               + ",BAKFARBE"
               + ",BAKKART"
               + ",BAKKVAR"
               + ",BAKKFARBE"
               + ",BAKPATT"
               + ",BAKPOS"
               + ",BAKANZ"
               + ",BAKABF"
               + " FROM INTEX.BASTKE WHERE RowNum<1");
                TableQueue.Enqueue("BSFARB");
                TableQueue.Enqueue("SELECT  "
                    + "BSFKART"
                    + ",BSFKVAR"
                    + ",BSFKFARBE "
                    + ",BSFBEZ"
                + " FROM INTEX.BSFARB WHERE RowNum<1");
                TableQueue.Enqueue("BASTGA");
                TableQueue.Enqueue("SELECT "
                + "BAGFDZ"
                + ",BAGART"
                + ",BAGVAR"
                + ",BAGFARBE"
                + ",BAGPOS"
                + ",BAGGART"
                + ",BAGGVAR"
                + ",BAGGFARBE"
                + ",BAGFDZ"
                + ",BAGKGNET"
                + ",BAGKGBRUT"
                + " FROM INTEX.BASTGA WHERE RowNum<1");
                TableQueue.Enqueue("WASTGA");
                TableQueue.Enqueue("SELECT  "
                       + "WAGART"
                + ",WAGVAR"
                + ",WAGWCOL"
                + ",WAGPSA"
                + ",WAGPOS"
                + ",WAGGART"
                + ",WAGGVAR"
                + ",WAGGFARBE"
                + ",WAGFDZ"
                + ",WAGKGNET"
                + ",WAGKGBRUT"
                + ",WAGEAFAKTOR"
                + ",WAGBEM"
                + " FROM INTEX.WASTGA WHERE RowNum<1");
                TableQueue.Enqueue("GSDAT");
                TableQueue.Enqueue("SELECT "
                + " GSART"
                + " ,GSVAR"
                + " ,GSMAT"
                + " ,GSNUMART"
                + " ,GSGARNNR"
                + " ,GSFACH"
                + " ,GSRECHNUM"
                + " ,GSRECHNR"
                 + " FROM INTEX.GSDAT WHERE RowNum<1");
                TableQueue.Enqueue("GASTGA");
                TableQueue.Enqueue("SELECT "
                    + "GAGART"
                    + ",GAGVAR"
                    + ",GAGFARBE"
                    + ",GAGPOS"
                    + ",GAGGART"
                    + ",GAGGVAR"
                    + ",GAGGFARBE"
                    + ",GAGKGNET"
                    + ",GAGKGBRUT"
                   + " FROM INTEX.GASTGA Where RowNum<1");
                TableQueue.Enqueue("GSCOLOR");
                TableQueue.Enqueue("SELECT GSCART,GSCVAR,GSCFARBE,GSCBEZ FROM INTEX.GSCOLOR WHERE RowNum<1");
                while (TableQueue.Count > 0)
                {
                    string TableName = TableQueue.Dequeue() as string;
                    string QueryStr = TableQueue.Dequeue() as string;
                    if (!dsTarget.Tables.Contains(TableName))
                    {
                        orlReadCommand = OracleDB.CreateCommand();
                        orlReadCommand.CommandText = QueryStr;
                        setResult = Connect2Proxy(orlReadCommand);
                        if (setResult.Tables.Count > 0)
                        {
                            setResult.Tables[0].TableName = TableName;
                        }
                        foreach (DataTable dtTemp in setResult.Tables)
                        {
                            dsTarget = ImportDataTable(dsTarget, dtTemp);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return dsTarget;
        }
        public GreigeMasterData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }
        public DataSet GetGreigeMaster(DataSet dsTarget, DataRow dwWAFARBEN)
        {
            try
            {
                #region WASTAMM
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT WAART " +
                ",WAVAR" +
                ",WAAENB" +
                ",WAPROGRP" +
                ",WAARTGRP" +
                ",WARSTAKZ" +
                ",WAVWART" +
                ",WAVWVAR" +
                ",WAFFDDIK" +
                ",WAFFDDIS" +
                ",WAFDDIM" +
                ",WARFDDIK" +
                ",WARFDDIS" +
                ",WAFBRTL" +
                ",WARWBRT" +
                ",WAFGRQM" +
                ",WARGRQM" +
                ",WAFGRLFD" +
                ",WARGRLFD" +
                ",WABIND" +
                ",WAEINZNR" +
                ",WARSTDLG" +
                ",WARSTDGW" +
                ",WARFDDIS" +
                ",WALAEAEND as FEnlongation" +
                ",WATEXTE1" +
                ",WATEXTE2" +
                ",WATEXTE3" +
                ", WAART as ComEN" +
                ", WAART as ComCN" +
                " FROM INTEX.WASTAMM WHERE WAART =:ArticleNum AND WAVAR=:ArticleVar";
                orlReadCommand.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                orlReadCommand.Parameters.Add("ArticleVar", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                setResult = Connect2Proxy(orlReadCommand);

                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WASTAMM";
                    Queue Q10 = new Queue();
                    Q10.Enqueue("WAFBRTL");
                    Q10.Enqueue("WARWBRT");
                    Queue Q100 = new Queue();
                    Q100.Enqueue("WAFFDDIK");
                    Q100.Enqueue("WAFFDDIS");
                    Q100.Enqueue("WARFDDIK");
                    Q100.Enqueue("WARFDDIS");
                    Q100.Enqueue("FEnlongation");
                    Queue Q1000 = new Queue();
                    Q1000.Enqueue("WARSTDLG");
                    Q1000.Enqueue("WARSTDGW");

                    DivideBy10(setResult.Tables[0], Q10);
                    DivideBy100(setResult.Tables[0], Q100);
                    DivideBy1000(setResult.Tables[0], Q1000);

                }
                DataTable dtWASTAMM = setResult.Tables["WASTAMM"];
                foreach (DataRow dwWASTAMM in dtWASTAMM.Rows)
                {
                    string WATEXTE1 = dwWASTAMM["WATEXTE1"].ToString();
                    dwWASTAMM["WATEXTE1"] = GetCommentsFromTXTIND("WKT", WATEXTE1);
                    string WATEXTE2 = dwWASTAMM["WATEXTE2"].ToString();
                    dwWASTAMM["WATEXTE2"] = GetCommentsFromTXTIND("WKT", WATEXTE2);
                    string WATEXTE3 = dwWASTAMM["WATEXTE3"].ToString();
                    dwWASTAMM["WATEXTE3"] = GetCommentsFromTXTIND("WKT", WATEXTE3);
                }
                #endregion

                #region Compostion
                string ArticleNum = dwWAFARBEN["WAFART"].ToString();
                string ArticleVar = dwWAFARBEN["WAFVAR"].ToString();
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT STUELISAPD,STUELIPPOS as POS,STUELISASB as COM, STUELISASB as CNName, STUELIDATEN as Portion " +
                " FROM INTEX.STUELI WHERE STUELISAPD like '%" +
                ArticleNum + "%" +
                ArticleVar + "%'";

                setResult = Connect2Proxy(orlReadCommand);

                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WSCOMPOSITION";

                }

                DataTable dtWSCOM = setResult.Tables["WSCOMPOSITION"];
                string Client = "00";
                string Lang = "V";
                string COM = "";
                string strCom = "                     ";//22
                string POS = "";
                string CNName = "";
                double Portion = 0.0;
                string ComEN = "";
                string ComCN = "";


                foreach (DataRow dsWSCOM in dtWSCOM.Rows)
                {
                    POS = dsWSCOM["POS"].ToString();
                    COM = dsWSCOM["COM"].ToString();
                    CNName = Client + (COM + strCom).Substring(0, 21) + Lang;
                    CNName = GetDataFromSDDAT("0013", CNName);
                    dsWSCOM["CNName"] = CNName;
                    Portion = System.Convert.ToDouble(dsWSCOM["Portion"].ToString().Substring(0, 4)) / 10.00;
                    ComEN += COM.TrimEnd() + Math.Round(Portion, 2).ToString().Trim() + "%  ";
                    ComCN += CNName + Math.Round(Portion, 2).ToString().Trim() + "%  ";
                }
                if (dtWASTAMM.Rows.Count > 0)
                {
                    dtWASTAMM.Rows[0]["ComEN"] = ComEN;
                    dtWASTAMM.Rows[0]["ComCN"] = ComCN;
                }
                dsTarget = ImportDataTable(dsTarget, dtWASTAMM);
                //dsTarget = ImportDataTable(dsTarget, dtTemp);  
                #endregion
                //select * from STUELI where rownum<10 and STUELISAPD like '%PV912102            A1 %'


            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return dsTarget;
        }
        public DataTable GetGreigeColorWay(DataTable dtTarget, DataRow dwWAFARBEN)
        {
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT WAFART as ArtNum,	WAFVAR as ArtVar,	 WAFZUSATZ as ArtColor,WAFBEZ as ColorDes"
                    + "  FROM INTEX.WAFARBEN WHERE WAFART = :ArticleNum AND WAFVAR=:ArticleVar AND WAFZUART='C'";
                orlReadCommand.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                orlReadCommand.Parameters.Add("ArticleVar", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "ARTICLECOLOR";
                    dtTarget = setResult.Tables[0];
                    setResult.AcceptChanges();
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return dtTarget;
        }
        public DataTable GetGreigeFinish(DataTable dtTarget, DataRow dwWAFARBEN)
        {
            try
            {

                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT WAFART as ArtNum,	WAFVAR as ArtVar,	 WAFZUSATZ as ArtFin,WAFBEZ as FinishDes"
    + "  FROM INTEX.WAFARBEN WHERE WAFART = :ArticleNum AND WAFVAR=:ArticleVar AND WAFZUART='B'";
                orlReadCommand.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                orlReadCommand.Parameters.Add("ArticleVar", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "ARTICLEFINISH";
                    dtTarget = setResult.Tables["ARTICLEFINISH"];
                    setResult.AcceptChanges();
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return dtTarget;
        }
        public DataTable GetGreigeVariant(DataTable dtTarget, DataRow dwWAFARBEN)
        {
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT WAVAR as ArtVar "
                    + "  FROM INTEX.WASTAMM WHERE WAART = :ArticleNum";
                orlReadCommand.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "ARTICLEVAR";
                    dtTarget = setResult.Tables[0];
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return dtTarget;
        }
        public DataSet GetGreigeColorWay(DataSet dsTarget, DataRow dwWAFARBEN)
        {
            try
            {
                OracleCommand or1;
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT WAFART, WAFVAR,WAFZUART,WAFZUSATZ,WAFZUSATZ as WAFCOLORIT,'' as COMS" +
                    " FROM INTEX.WAFARBEN WHERE WAFART = :WAFART AND WAFVAR=:WAFVAR AND WAFZUSATZ=:WAFZUSATZ";

                or1.Parameters.Add("WAFART", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                or1.Parameters.Add("WAFVAR", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                or1.Parameters.Add("WAFZUSATZ", OracleType.NVarChar).Value = dwWAFARBEN["WAFZUSATZ"].ToString();
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WAFARBEN";
                }
                foreach (DataRow rowWAFARBEN in setResult.Tables["WAFARBEN"].Rows)
                {
                    DataSet setUI = new DataSet();
                    try
                    {

                        string COMMENTS = "";
                        orlReadCommand = OracleDB.CreateCommand();
                        orlReadCommand.CommandText = "SELECT trim(TXTKTEXT) AS COMS "
                            + " FROM TXTIND A,TXTKON B WHERE A.TXTIMANDANT = B.TXTKMANDANT "
                            + " AND A.TXTIPIND = B.TXTKPIND AND B.TXTKPOS >40 AND A.TXTITXTART = 'WAE' "
                            + " AND SUBSTR(A.TXTISIND,15,20) = :ArticleNum "
                            + " AND SUBSTR(A.TXTISIND,35,2)= :ArticleVar AND SUBSTR(A.TXTISIND,37,1)='C' "
                            + " AND SUBSTR(A.TXTISIND,38,10) = :ArticleColor ";
                        orlReadCommand.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = rowWAFARBEN["WAFART"].ToString();
                        orlReadCommand.Parameters.Add("ArticleVar", OracleType.NVarChar).Value = rowWAFARBEN["WAFVAR"].ToString();
                        orlReadCommand.Parameters.Add("ArticleColor", OracleType.NVarChar).Value = rowWAFARBEN["WAFZUSATZ"].ToString();
                        setUI = Connect2Proxy(orlReadCommand);

                        if (setUI.Tables.Count > 0)
                        {
                            setUI.Tables[0].TableName = "WAFARBENCOMS";
                            foreach (DataRow rowTemp1 in setUI.Tables["WAFARBENCOMS"].Rows)
                            {

                                COMMENTS += rowTemp1["COMS"].ToString() + Environment.NewLine;
                            }
                        }
                        if (COMMENTS != "")
                        {
                            rowWAFARBEN["COMS"] = COMMENTS;
                        }
                    }
                    catch (Exception ex)
                    {
                        Tracer.Error(ex.StackTrace, ex);
                    }
                }
                foreach (DataTable dtTemp in setResult.Tables)
                {
                    if (dsTarget.Tables.Contains("WAFARBEN"))
                    {
                        dsTarget.Tables["WAFARBEN"].Clear();
                        dsTarget.AcceptChanges();
                    }
                    dsTarget = ImportDataTable(dsTarget
                   , FilterByColor(setResult.Tables["WAFARBEN"],
                   "WAFZUSATZ",
                   dwWAFARBEN["WAFZUSATZ"].ToString()));
                }
                dsTarget.Merge(setResult);

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return dsTarget;
        }
        public DataSet GetWarpBeamKey(DataSet dsTarget, DataRow dwWAFARBEN)
        {
            try
            {
                ///
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT  " +
                    "WAKART" +
                ",WAKWCOL" +
                ",WAKPOS" +
                ",WAKKART" +
                ",WAKKVAR" +
                ",WAKKFARBE" +
                ",WAKEAFAKTR" +
                ",WAKLLEIST" +
                ",WAKRLEIST" +
                    " FROM INTEX.WASTKE WHERE WAKART = :WAKART AND WAKVAR=:WAKVAR AND WAKWCOL=:WAKWCOL";
                orlReadCommand.Parameters.Add("WAKART", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                orlReadCommand.Parameters.Add("WAKVAR", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                orlReadCommand.Parameters.Add("WAKWCOL", OracleType.NVarChar).Value = dwWAFARBEN["WAFZUSATZ"].ToString();
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WASTKE";
                    Queue Q1000 = new Queue();
                    Q1000.Enqueue("WAKEAFAKTR");
                    DivideBy1000(setResult.Tables[0], Q1000);
                    /*
                    dsTarget = ImportDataTable(dsTarget
                   , FilterByColor(
                   setResult.Tables["WASTKE"],
                   "WAKWCOL",
                   dwWAFARBEN["WAFZUSATZ"].ToString())*/
                    dsTarget.Merge(setResult);
                }

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return dsTarget;
        }
        public DataSet GetWeftYarn(DataSet dsTarget, DataRow dwWAFARBEN)
        {
            try
            {

                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT  "
                       + "WAGART"
                + ",WAGVAR"
                + ",WAGWCOL"
                + ",WAGPSA"
                + ",WAGPOS"
                + ",WAGFOLGEPOS"
                + ",WAGGART"
                + ",WAGGVAR"
                + ",WAGGFARBE"
                + ",WAGFDZ"
                    + ",WAGABF"
                + ",WAGKGNET"
                + ",WAGKGBRUT"
                + ",WAGEAFAKTOR"
                + ",WAGBEM"
                + " FROM INTEX.WASTGA WHERE WAGPSA='1' AND WAGPOS='00' AND WAGART = :WAGART AND WAGVAR=:WAGVAR  AND WAGWCOL=:WAGWCOL";
                orlReadCommand.Parameters.Add("WAGART", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                orlReadCommand.Parameters.Add("WAGVAR", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                orlReadCommand.Parameters.Add("WAGWCOL", OracleType.NVarChar).Value = dwWAFARBEN["WAFZUSATZ"].ToString();
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WASTGA";
                    Queue Q1000 = new Queue();
                    Q1000.Enqueue("WAGKGNET");
                    Q1000.Enqueue("WAGKGBRUT");
                    DivideBy1000(setResult.Tables[0], Q1000);
                    Queue Q100 = new Queue();
                    Q100.Enqueue("WAGABF");
                    DivideBy100(setResult.Tables[0], Q100);
                    dsTarget.Merge(setResult);
                    /*
                    dsTarget = ImportDataTable(dsTarget,
                    FilterByColor(
                    setResult.Tables["WASTGA"]
                    , "WAGWCOL"
                    , dwWAFARBEN["WAFZUSATZ"].ToString()));
                    */
                }

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return dsTarget;
        }
        public DataSet GetTechnicalData(DataSet dsTarget, DataRow dwWAFARBEN)
        {
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT WTGART" +
                    ",WTGVAR" +
                    ",WTGWBBRT" +
                    ",WTGWBBRT-30 as InnerReed" +
                    ",WTGWBF" +
                    ",WTGFDISM" +
                    ",WTGFDLGS" +
                    ",WTGFDLFS" +
                    ",WTGSFLG" +
                    ",WTGKCOL" +
                    ",WTGSMTRS" +
                    " FROM INTEX.WTGEW WHERE WTGART = :ArticleNum AND WTGVAR=:ArticleVar";
                orlReadCommand.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                orlReadCommand.Parameters.Add("ArticleVar", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WTGEW";
                    Queue Q10 = new Queue();
                    Q10.Enqueue("WTGWBBRT");
                    Q10.Enqueue("InnerReed");
                    Q10.Enqueue("WTGFDLGS");
                    Q10.Enqueue("WTGFDLFS");
                    Queue Q100 = new Queue();
                    Q100.Enqueue("WTGWBF");
                    Q100.Enqueue("WTGFDISM");
                    Q100.Enqueue("WTGSMTRS");
                    DivideBy10(setResult.Tables[0], Q10);
                    DivideBy100(setResult.Tables[0], Q100);
                }
                foreach (DataTable dtTemp in setResult.Tables)
                {
                    dsTarget = ImportDataTable(dsTarget, dtTemp);
                }

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return dsTarget;
        }
        public DataSet GetPatternKey(DataSet dsTarget, DataRow dwWAFARBEN)
        {
            try
            {
                // 
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT * FROM INTEX.WASTPASS WHERE WSPART = :ArticleNum AND WSPVAR=:ArticleVar";
                orlReadCommand.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                orlReadCommand.Parameters.Add("ArticleVar", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WASTPASS";
                }
                foreach (DataTable dtTemp in setResult.Tables)
                {
                    dsTarget = ImportDataTable(dsTarget, dtTemp);
                }

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return dsTarget;
        }
        public DataSet BuildGreigeMasterData(DataSet dsTarget, DataRow dwWAFARBEN)
        {
            try
            {
                dsTarget = GetGreigeMaster(dsTarget, dwWAFARBEN);

                dwWAFARBEN["WAFART"] = dsTarget.Tables["WASTAMM"].Rows[0]["WAVWART"];
                dwWAFARBEN["WAFVAR"] = dsTarget.Tables["WASTAMM"].Rows[0]["WAVWVAR"];
                dsTarget = GetGreigeColorWay(dsTarget, dwWAFARBEN);
                dsTarget = GetTechnicalData(dsTarget, dwWAFARBEN);
                dsTarget = GetPatternKey(dsTarget, dwWAFARBEN);
                dsTarget = GetWarpBeamKey(dsTarget, dwWAFARBEN);
                dsTarget = GetWeftYarn(dsTarget, dwWAFARBEN);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return dsTarget;
        }

        #region ----------------EDIT-------------------------
        public void ComputeWeftQuantity(DataRow dwWASTAMM, DataRow dwWTGEW, ref DataRow dwWASTGA)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            string weftPattern = "", GSVAR, GSART, GSRECHNUM;
            double CountYarn, WAGFDZ, WTSSRAPP, WARSTDLG, WARFDDIS, in2cm, lenYarn, WTGFDLGS, mt2cm, mtr2yd, GSRECHNR, pound2kg, WAGABF, WAGKGNET, WAGKGBRUT;
            in2cm = 2.54;
            mt2cm = 100.00;
            mtr2yd = 0.9144;
            pound2kg = 0.4536;
            try
            {
                WAGFDZ = System.Convert.ToDouble(dwWASTGA["WAGFDZ"].ToString());
                WARSTDLG = System.Convert.ToDouble(dwWASTAMM["WARSTDLG"].ToString()) * 0.001;
                WARFDDIS = System.Convert.ToDouble(dwWASTAMM["WARFDDIS"].ToString()) * 0.01;
                WTGFDLGS = System.Convert.ToDouble(dwWTGEW["WTGFDLGS"].ToString()) * 0.1;
                GSART = dwWASTGA["WAGGART"].ToString();
                GSVAR = Left(dwWASTGA["WAGGVAR"].ToString() + "   ", 3);
                or1.CommandText = "SELECT * FROM GSDAT WHERE GSMANDANT='00' AND GSART='" + GSART + "' AND GSVAR='" + GSVAR + "'";
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count == 0)
                {
                    return;
                }
                GSRECHNUM = setResult.Tables[0].Rows[0]["GSRECHNUM"].ToString();
                GSRECHNR = System.Convert.ToDouble(setResult.Tables[0].Rows[0]["GSRECHNR"].ToString()) * 0.0001;
                GSRECHNR = TONE(GSRECHNR, GSRECHNUM.Trim());
                weftPattern = dwWTGEW["WTGSFLG"].ToString();
                or1.CommandText = "SELECT * FROM WTSCHUSS WHERE WTSMANDANT='00' AND WTSSFLGNR='" + weftPattern + "'";
                setResult = Connect2Proxy(or1);
                if (setResult.Tables[0].Rows.Count == 0)
                {
                    Tracer.Info("ComputeWeftQuantity", "请验证花型是否存在");
                    return;
                }
                WTSSRAPP = System.Convert.ToDouble(setResult.Tables[0].Rows[0]["WTSSRAPP"].ToString());
                CountYarn = ((WAGFDZ / WTSSRAPP) * WARSTDLG * 100 * WARFDDIS) / in2cm;
                lenYarn = CountYarn * WTGFDLGS / mt2cm;
                WAGKGNET = (lenYarn / mtr2yd) / (GSRECHNR * 840) * pound2kg;
                WAGKGNET = System.Math.Round(WAGKGNET * 1000, 0);
                dwWASTGA["WAGKGNET"] = WAGKGNET.ToString().Replace(".0", "");
                WAGABF = System.Convert.ToDouble(dwWASTGA["WAGABF"].ToString()) * 0.01 * 0.01;
                WAGKGBRUT = WAGKGNET * (1 + WAGABF);
                WAGKGBRUT = System.Math.Round(WAGKGBRUT, 0);
                dwWASTGA["WAGKGBRUT"] = WAGKGBRUT.ToString().Replace(".0", "");
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public DataSet GetRWS0305(DataRow dwWAFARBEN)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                DataTable tbLocal = null;
                #region WASTAMM
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT *  FROM INTEX.WASTAMM WHERE WAART =:ArticleNum AND WAVAR=:ArticleVar";
                orlReadCommand.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                orlReadCommand.Parameters.Add("ArticleVar", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    tbLocal = setResult.Tables[0];
                    tbLocal.TableName = "WASTAMM";
                }
                #endregion
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet GetRWS07(DataRow dwWAFARBEN, string WAFZUART, string WAFZUSATZ)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT * FROM INTEX.WAFARBEN WHERE WAFART = :WAFART AND WAFVAR=:WAFVAR AND WAFZUART=:WAFZUART AND WAFZUSATZ=:WAFZUSATZ ";
                //AND WAFZUSATZ=:ArticleColor";
                orlReadCommand.Parameters.Add("WAFART", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                orlReadCommand.Parameters.Add("WAFVAR", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                orlReadCommand.Parameters.Add("WAFZUART", OracleType.NVarChar).Value = WAFZUART;
                orlReadCommand.Parameters.Add("WAFZUSATZ", OracleType.NVarChar).Value = WAFZUSATZ;

                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WAFARBEN";
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet GetRWTGEW(DataRow dwWAFARBEN)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataTable tbWTGEW = setINTEX.WTGEW.Clone();
            setReturn.Merge(tbWTGEW);
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT * FROM INTEX.WTGEW WHERE WTGART = :ArticleNum AND WTGVAR=:ArticleVar";
                orlReadCommand.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                orlReadCommand.Parameters.Add("ArticleVar", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WTGEW";
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }

        public DataSet GetWS31(DataRow dwWAFARBEN)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                ///
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT * FROM INTEX.WASTKE WHERE WAKART = :WAKART AND WAKVAR=:WAKVAR AND WAKWCOL=:WAKWCOL";
                orlReadCommand.Parameters.Add("WAKART", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                orlReadCommand.Parameters.Add("WAKVAR", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                orlReadCommand.Parameters.Add("WAKWCOL", OracleType.NVarChar).Value = dwWAFARBEN["WAFZUSATZ"].ToString();
                //dwART["WAFZUSATZ"]
                //orlReadCommand.Parameters.Add("WAKWCOL", OracleType.NVarChar).Value =dwWAFARBEN["WAFZUSATZ"].ToString().Trim();
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WASTKE";
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet GetWS33(DataRow dwWAFARBEN)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {

                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT  * FROM INTEX.WASTGA "
                + " WHERE WAGPSA='1' AND WAGPOS='00' AND WAGART = :WAGART AND WAGVAR=:WAGVAR AND WAGWCOL=:WAGWCOL";
                orlReadCommand.Parameters.Add("WAGART", OracleType.NVarChar).Value = dwWAFARBEN["WAFART"].ToString();
                orlReadCommand.Parameters.Add("WAGVAR", OracleType.NVarChar).Value = dwWAFARBEN["WAFVAR"].ToString();
                orlReadCommand.Parameters.Add("WAGWCOL", OracleType.NVarChar).Value = dwWAFARBEN["WAFZUSATZ"].ToString();
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "WASTGA";
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet GetData(DataRow dwWAFARBEN, string color, string finish)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            string Article = (dwWAFARBEN["WAFART"].ToString().Trim()
                + "/" + dwWAFARBEN["WAFVAR"].ToString().Trim() + "/"
                + dwWAFARBEN["WAFZUSATZ"].ToString().Trim()).Trim();
            try
            {
                DataRow dwWASTAMM = null;
                setResult = GetRWS0305(dwWAFARBEN);
                setReturn.Merge(setResult);
                EventDispatcher.Instance.RaiseStatus("品种" + Article + " 已读取GetRWS0305", StatusEventType.RunningProgress);
                dwWASTAMM = setResult.Tables["WASTAMM"].Rows[0];
                dwWAFARBEN["WAFART"] = dwWASTAMM["WAART"];
                dwWAFARBEN["WAFVAR"] = dwWASTAMM["WAVAR"];
                setResult = GetRWTGEW(dwWAFARBEN);
                setReturn.Merge(setResult);
                EventDispatcher.Instance.RaiseStatus("品种" + Article + " 已读取GetRWTGEW", StatusEventType.RunningProgress);

                setResult = GetRWS07(dwWAFARBEN, "C", color);
                setReturn.Merge(setResult);

                setResult = GetRWS07(dwWAFARBEN, "B", finish);
                setReturn.Merge(setResult);

                EventDispatcher.Instance.RaiseStatus("品种" + Article + " 已读取GetRWS07", StatusEventType.RunningProgress);
                setResult = GetWS31(dwWAFARBEN);
                setReturn.Merge(setResult);
                EventDispatcher.Instance.RaiseStatus("品种" + Article + " 已读取GetWS31", StatusEventType.RunningProgress);

                setResult = GetWS33(dwWAFARBEN);
                setReturn.Merge(setResult);
                EventDispatcher.Instance.RaiseStatus("品种" + Article + " 已读取GetWS33", StatusEventType.RunningProgress);

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        #endregion
    }
}